<%@ Reference Control="~/Manager/Lib/Controls/TrackerTransactions.ascx" %>
<%@ Reference Control="~/Manager/Lib/Controls/Car.ascx" %>
<%@ Control Language="c#" Inherits="Dimok.Aspx.Manager.Lib.Controls.TrackerRequest" CodeFile="TrackerRequest.ascx.cs" %>
<%@ Register TagPrefix="Car"		 TagName="Car"					Src="/Manager/Lib/Controls/Car.ascx" %>
<%@ Register TagPrefix="Tracker" TagName="Transactions" Src="/Manager/Lib/Controls/TrackerTransactions.ascx" %>
<%@ Register TagPrefix="Tracker" TagName="Licenses" Src="/Manager/Lib/Controls/TrackerLicenses.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<META name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"><META name="CODE_LANGUAGE" Content="C#"><META name="vs_defaultClientScript" content="JavaScript"><META name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<?XML:NAMESPACE PREFIX="WM"/>
<?XML:NAMESPACE PREFIX="COOL"/>
<?XML:NAMESPACE PREFIX="DIMOK"/>
<?IMPORT namespace="DIMOK" implementation="/include/htc/datagrid.htc">
<LINK rel="stylesheet" type="text/css" href="/CSS/navbar.css">
<LINK rel="stylesheet" type="text/css" href="/CSS/Outlook.css">
<SCRIPT src="/include/common.js"></SCRIPT>
<SCRIPT src="/include/soap.js"></SCRIPT>
<SCRIPT src="/include/XML.js"></SCRIPT>
<SCRIPT src="/include/RDS.js"></SCRIPT>
<SCRIPT src="/include/Events.js"></SCRIPT>
<SCRIPT src="/include/VIN.js"></SCRIPT>
<SCRIPT src="/Include/DropMenu.js"></SCRIPT>
<SCRIPT src="/manager/common/common.js"></SCRIPT>
<STYLE>
WM\:DROPMENU { BEHAVIOR: url(/include/HTC/dropmenu_d.htc) }
cool\:tip{behavior: url(/Include/HTC/cooltip_js.htc)}
.cell {BORDER:1 black solid;background-color:white;width:100%;padding:1px}
CAPTION {BEHAVIOR: url(/Include/HTC/Toggle.htc);white-space:nowrap}
LEGEND {BEHAVIOR: url(/Include/HTC/Toggle.htc);white-space:nowrap}
</STYLE>
<XML id="XmlTrackerRequestNotes"><ASP:LITERAL id="ltrTrackerRequestNotes" Runat="server"></ASP:LITERAL></XML>
<XML id="XmlTrackerRequestNotesList"><ASP:LITERAL id="ltrTrackerRequestNotesList" Runat="server"></ASP:LITERAL></XML>
<XML id="XmlTrackerRequest"><ASP:LITERAL ID="ltrTrackerRequest" Runat="server"></ASP:LITERAL></XML>
<XML id="XmlTrackers"><ASP:LITERAL ID="ltrTrackers" Runat="server"></ASP:LITERAL></XML>
<COOL:TIP id="oTip" avoidmouse="true" DURATION="30"></COOL:TIP>
<TABLE id="tblCarInfo" wsMethod="TrackerRequest_Update" border="0">
	<TR>
		<TD>Request ID
		<TD style="PADDING-RIGHT: 3px; PADDING-LEFT: 3px" align="right">:
		<TD>
			<DIV datasrc="#XmlTrackerRequest" datafld="TrackerRequestID" style="overflow-x:visible;BORDER:1 solid black;PADDING:1px;MARGIN:1px;width:auto" nowrap></DIV>
		<TD rowspan="5" valign="top">
			<TRACKER:LICENSES runat="server" caption="Tracker Licenses"></TRACKER:LICENSES>
			<TRACKER:LICENSES runat="server" caption="Tracker Licenses(Prev)" id="tlPrev"></TRACKER:LICENSES>
	<TR>
		<TD>Dealer</TD>
		<TD style="PADDING-RIGHT: 3px; PADDING-LEFT: 3px" align="right">:</TD>
		<TD><SELECT datasrc="#XmlTrackerRequest" datafld="DealerID" id="selDealers"
								style="FONT-SIZE: 80%; TEXT-TRANSFORM: uppercase"
								onchange="return UF(undefined,undefined,undefined,undefined,_trackerRequestID())"
								runat="server"></SELECT>
		</TD>
	</TR>
	<TR>
		<TD>VIN
		<TD style="PADDING-RIGHT: 3px; PADDING-LEFT: 3px" align="right">:</TD>
		<TD>
			<DIV datasrc="#XmlTrackerRequest" datafld="VIN" size="18" style="overflow-x:visible;BORDER:1 solid black;PADDING:1px;MARGIN:1px;width:auto" nowrap></DIV>
		</TD>
	</TR>
	<TR valign="top">
		<TD>Trackers</TD>
		<TD style="PADDING-RIGHT: 3px; PADDING-LEFT: 3px" align="right">:</TD>
		<TD>
			<TABLE datasrc="#XmlTrackers" cellpadding="0" cellspacing="0" style="BEHAVIOR:URL(/include/HTC/TableDataSrc.htc)"><TR>
				<TD nowrap style="border-top:1 solid black;border-left:1 solid black;border-bottom:1 solid black" >
					<SPAN onclick="showAirCeptHistory(innerText,getParentTR(this).all['chkLocate'].checked);getParentTR(this).all['chkLocate'].checked=false" title="Click to see history" datafld="TrackerID" class="ReadOnly" style="margin-bottom:3px;VERTICAL-ALIGN: middle;cursor:hand"></SPAN>
				</TD>
				<TD style="border-top:1 solid black;border-right:1 solid black;border-bottom:1 solid black" nowrap>
					<INPUT type="checkbox" id="chkLocate" style="BORDER:none" NAME="chkLocate"> <LABEL for="chkLocate">Locate</LABEL>
				</TD>
				<TD nowrap style="padding-left:5px">
					<SPAN onclick="TechnicianInfo(this)" datafld="Technician" title="Click to installer info" style="FONT-SIZE: 85%; MARGIN-BOTTOM: 3px; VERTICAL-ALIGN: middle;cursor:hand" onmouseover="coolTip=rsField(this,'ToolTip').value;oTip.element=this"></SPAN>
				</TD>
			</TR></TABLE>
		</TD>
	</TR>
	<TR>
		<TD colspan="3">
			<CAR:CAR runat="server" id="car" style="width:100%"
							onvinchange="doTrackerRequestVinChange()"
							onbookvaluechange='status=event.type+":"+new Date()'
							onmileagechange='status=event.type+":"+new Date()'
			></CAR:CAR>
		</TD>
	</TR>
	<TR>
		<TD>Status</TD>
		<TD style="PADDING-RIGHT: 3px; PADDING-LEFT: 3px" align="right">:</TD>
		<TD colspan="2">
			<FIELDSET style="width:1%">
				<LEGEND state="+" PlusLast ontoggle="" noTip>
					<SELECT datasrc="#XmlTrackerRequest" datafld="StatusID" onchange="if(!confirm('Change status?'))return this.value=null;return UF_ReqSt(undefined,undefined,undefined,undefined,_trackerRequestID())" id="selRequestStatus" runat="server"></SELECT><INPUT type="button" value="Log" tabindex="-1" class="TipMe" coolTip="Co-o-o-ol1" onclick="TrackerRequest_History(this)" event="onclick"></LEGEND>
				<DIV nowrap style="display:none">
					<DIV>
						<TABLE datasrc="#XmlTrackerRequestNotes" border="1" cellpadding="0" cellspacing="0" style="BORDER-COLLAPSE: collapse">
							<THEAD>
								<TR>
									<TD colspan="10">
										<INPUT id="txtTrackerRequestNote" onupdate="TrackerRequest_Note(this)" style="width:100%;BEHAVIOR: URL(/include/HTC/BigList.htc); OVERFLOW-X: visible" xmlSrc="XmlTrackerRequestNotesList" textField="Note" loose>
									</TD>
								</TR>
								<TR><TH>Status</TH><TH>Note</TH><TH>When</TH><TH>Who</TH></TR>
							</THEAD>
							<TR valign="top">
								<TD nowrap><SPAN datafld="Status"></SPAN></TD>
								<TD><SPAN datafld="Note" style="WIDTH: 60mm"></SPAN></TD>
								<TD><SPAN datafld="DateStamp"></SPAN></TD>
								<TD><SPAN datafld="UserName"></SPAN></TD>
							</TR>
						</TABLE>
					</DIV>
				</DIV>
			</FIELDSET>
		</TD>
	</TR>
	<TR valign="top">
		<TD>Installer</TD>
		<TD style="PADDING-RIGHT: 3px; PADDING-LEFT: 3px" align="right">:</TD>
		<TD colspan="2">
			<FIELDSET style="width:1%">
				<LEGEND state="+" PlusLast style="VERTICAL-ALIGN: middle" noTip>
					<SELECT datasrc="#XmlTrackerRequest" datafld="TechnicianID" onchange="UF_Tech(undefined,undefined,undefined,undefined,_trackerRequestID());parentElement.state='-'" id="selTechnician" runat="server" NAME="selTechnician"></SELECT>
				</LEGEND>
				<DIV nowrap style="display:none">
				<DIV>Trackers :<INPUT type="button" value="Add" onclick="TrackerCar_Installed()"></DIV>
				<SELECT id="selTechTrackers" multiple size="8" ondblclick="showTracker(this.value)" title="Double-click to see Tracker Info" tabindex="-1"
								oncontextmenu="return showTrackerMenu()"
				>
					<ASP:LITERAL ID="ltrTechTrackers" Runat="server" />
				</SELECT>
				<BR>
				<DIMOK:HTCDATAGRID id="dtgTechRequests" caption="Active Tracker Requests"
								allowEdit="false" allowAdd="false" allowDelete="false"
								style="height:100%;overflow-x:visible"
								hiddenFields="TrackerRequestID" maxrecords="500"
								onFilter=""
								onrowselected="doOnSelect(undefined,undefined,showTrackerRequest)"
								onrowclick   ="doOnSelect(undefined,undefined,showTrackerRequest)"
				>
							<ASP:LITERAL ID="adoTechRequests" Runat="server"></ASP:LITERAL>
				</DIMOK:HTCDATAGRID>
				</DIV>
			</FIELDSET>
			<TABLE datasrc="#XmlTechRating" style="BEHAVIOR: url(/Include/HTC/rowover_js.htc)"
						 SELECTABLE="1">
				<CAPTION align="left" state="+">Installer Ratings</CAPTION>
				<THEAD bgcolor="InactiveCaption" style="COLOR: captiontext" style="display:none">
					<TR><TH>Name</TH><TH>Distance</TH><TH>Pending</TH><TH>Total</TH></TR></THEAD>
				<TBODY style="display:none">
				<TR align="center">
					<TD align="right"><B><SPAN datafld="Name"></SPAN></B></TD>
					<TD><SPAN datafld="Distance"></SPAN></TD>
					<TD><SPAN datafld="Pending"></SPAN></TD>
					<TD><SPAN datafld="Total"></SPAN></TD>
				</TR>
				</TBODY>
			</TABLE>
		</TD>
	</TR>
</TABLE>
<TRACKER:TRANSACTIONS id="trackerTrans" runat="server"></TRACKER:TRANSACTIONS>
<DIV id="divRegHist" style="display:none">
<TABLE datasrc="#xmlReqHist" style="FONT: statusbar; BORDER-COLLAPSE: collapse" border="1" bordercolor="black" onreadystatechange="if(document.body.funcResize)document.body.funcResize()">
	<THEAD><TR><TH>When</TH><TH>Status</TH><TH>Installer</TH><TH>Dealer</TH><TH>Who</TH></TR></THEAD>
	<TR>
		<TD nowrap><SPAN datafld="When"></SPAN></TD>
		<TD nowrap><SPAN datafld="Status"></SPAN></TD>
		<TD nowrap><SPAN datafld="Installer"></SPAN></TD>
		<TD nowrap><SPAN datafld="DealerName"></SPAN></TD>
		<TD nowrap><SPAN datafld="Who"></SPAN></TD>
	</TR>
</TABLE>
<XML id="xmlReqHist">[xml]</XML>
</DIV>
<XML id="XmlTechRating"><ASP:LITERAL runat="server" id="ltrTechRating"></ASP:LITERAL></XML>
<ASP:LITERAL runat="server" id="ltrScript"></ASP:LITERAL>
<SCRIPT language="javascript">
initWS("Common","../Common/Common.asmx");
if( !this.frameElement )window.attachEvent("onresize",doResize);
title.load("WIN_WH");
var UF_ReqSt = UF_AddCallBacks("UF_ReqSt",changeRequestStatus);
var UF_Tech  = UF_AddCallBacks("UF_Tech" ,changeTechnician);
function doResize(ev){
	title.setAttribute("WIN_W",document.body.offsetWidth+8);
	title.setAttribute("WIN_H",document.body.offsetHeight+31);
	title.save("WIN_WH");
}
attachEvent("onload",load_Page);
function load_Page(){
	//attachToTrackerRequestStatus(document.location.reload,ApplID());
	//cropWindow();
	if( !this.frameElement )
		try{
			top.focus();
			resizeTo(title.getAttribute("WIN_W"),title.getAttribute("WIN_H"));
		}catch(e){}
}
function showTrackerMenu(){
	var e = event.srcElement;
	var menu = new DropMenu("mnuFly");
	if( !menu.menuID )return false;
	menu.imageStyle += ";margin-top:0px;margin-bottom:0px";
	menu.add("Copy","copyElement(ce.value)");
	menu.menuShow(getLeftPos(e)+e.offsetWidth,event.y/*-event.offsetY+e.offsetHeight*/-3);
	event.cancelBubble = true;
	return false;
}
function TrackerRequest_Note(el){
	var ret = WS(CO(),_trackerRequestID(),el.Text);
	if( showSOAPError(ret) )return;
	var rsTrackerRequestNotes = getRSFromDS(ret.value);
	if( !updateRS(XmlTrackerRequestNotes.recordset,rsTrackerRequestNotes ) )
		XmlTrackerRequestNotes.loadXML(ret.value);
	el.value = "";
}
function doTrackerRequestVinChange(){
	var ret = WS(CO("TrackerRequest_LoanID"),_trackerRequestID());
	if( showSOAPError(ret) )return event.returnValue = false;
	var updateLoan = ret.value > 0 ? messageBox("Update loan "+ret.value+" with new VIN?") : false;
	if( updateLoan === null )return event.returnValue = false;
	var ret = WS(CO("TrackerRequest_VIN"),_trackerRequestID(),event.VIN||null,updateLoan);
	if( showSOAPError(ret) )return event.returnValue = false;
	//_rsTrackerRequest("VIN").value = event.VIN;
	refreshAll(ret);
}
function changeRequestStatus(ret,el,fieldName,fieldValue,wsMethod){
	if( fieldName != "StatusID" )return;
	refreshAll(ret);
	refreshList();
	trackerTrans.doFilter("TechnicianID="+_technicianID());
	refreshTLs();
}
function refreshTLs(){
	tlPrev.rs = trackerLicenses.rs;
	trackerLicenses.PurchaseLicenses();
}
function changeTechnician(ret,el,fieldName,fieldValue,wsMethod){
	if( fieldName != "TechnicianID" )return;
	TechnicianTracker_InHands(el,getRSFromDS(ret.value,"TechTrackers"));
	dtgTechRequests.recordset = getRSFromDS(ret.value,"TechRequests")("AdoString").value;
	trackerTrans.doFilter(fieldName+"="+fieldValue);
}
function TechnicianTracker_InHands(el,rs){
	if( !rs ){
		var ret = WS(CO(getFuncName()),el.value);
		if( showSOAPError(ret) )return;
		rs = 	getRSFromDS(ret.value);
	}
	fillSelect(rs,selTechTrackers,"TrackerID","TrackerID");
	setTimeout(function(){document.body.focus()},100);
}
function refreshList(){fireListRefresh({menuPath:"Tracking ->"});}
function refreshAll(ret){
	fillSelect(getRSFromDS(ret.value,"Statuses"),selRequestStatus,"MenuName","MenuID");
	updateRS(XmlTrackerRequest.recordset,getRSFromDS(ret.value,"TrackerRequest"));
	XmlTrackers.loadXML(getTableFromDS(ret.value,"Trackers"));
	car.xmlTrackers = getTableFromDS(ret.value,"TrackersByVIN");
	if( car.VIN != _VIN() )car.VIN = _VIN();
	fillSelect(getRSFromDS(ret.value,"TechTrackers"),selTechTrackers,"TrackerID","TrackerID",selTechTrackers.value);
	dtgTechRequests.recordset = getRSFromDS(ret.value,"TechRequests")("AdoString").value;
	return;//*******************************************************************************
	fillSelect(getRSFromDS(ret.value,"Statuses"),selRequestStatus,"MenuName","MenuID");
	var rsTrackersNew = getRSFromDS(ret.value,"Trackers");
	if( !updateRS(_carInfo().rsTrackers,rsTrackersNew ) )
		_carInfo().xmlTrackers = getDSFromRS(rsTrackersNew).xml;
	fillSelect(getRSFromDS(ret.value,"TechTrackers"),selTechTrackers,"TrackerID","TrackerID");
}
function showTable(table){
	var b0 = table.tBodies[0];
	if( !b0 || table.readyState != "complete" )return;
	b0.style.display = isXmlRSEmpty(eval(table.dataSrc.substr(1)).recordset) ? "none" : "";
}
function TrackerCar_Installed(){
	if( !selTechTrackers.value )return alert("Select tracker(s).");
	if( !eval(selTechnician.value) )return alert("Select Installer.");
	var trackers = _trackerIDs(selTechTrackers);
	if( !confirm("Add tracker(s): "+trackers+"?") )return;
	var ret = WS(CO(),_trackerRequestID(),trackers);
	if( showSOAPError(ret) )return;
	refreshList();
	refreshAll(ret);
	refreshTLs();
	//Locals
	function _trackerIDs(sel){
		for( var i=0,a=[]; i < sel.length; i++ )
			if( sel[i].selected )a.push(sel[i].value);
		return a;
	}
}
function TrackerRequest_History(el){
	var ret = WS(CO(),_trackerRequestID());
	if( showSOAPError(ret) )return;
	el.coolTip = divRegHist.innerHTML.replace("[xml]",ret.value);
}
function showHist(columnName){//debugger;
	if( event.type == "keydown" && event.keyCode != 113 ){
		return;
	}
	columnName = columnName || document.activeElement.dataFld;
	if( !columnName )return alert("Select field first.");
	var ret = WS(CO("GetColumnHistory"),columnName);
	if( showSOAPError(ret) )return;
	grd.recordset = ret.value;
	grd.style.display = "";
}
function _carInfo(){return document.all.tags("CARINFO")[0];}
function _rsTrackerRequest(fieldName){
	if(arguments.length )return _rsTrackerRequest()(fieldName);
	return XmlTrackerRequest.recordset;
}
function _rsTrackers(fieldName){
	if(arguments.length )return arguments.callee()(fieldName);
	return XmlTrackers.recordset;
}
function _trackerRequestID(){return _rsTrackerRequest("TrackerRequestID").value}
function _technicianID(){return _rsTrackerRequest("TechnicianID").value}
function _dealerID(){return _rsTrackerRequest("DealerID").value}
function _VIN(){return _rsTrackerRequest("VIN").value}
</SCRIPT>
